# 应用主入口
from flask import Flask
# 从flask_sqlalchemy库导入SQLAlchemy，这是一个ORM工具
# ORM可以让我们用Python类来操作数据库，而不用直接写SQL语句
from flask_sqlalchemy import SQLAlchemy
from config import SQLALCHEMY_DATABASE_URI, SQLALCHEMY_TRACK_MODIFICATIONS
# 导入并注册路由
from routes import register_routes

# 初始化Flask应用
app = Flask(__name__)

# 配置数据库
app.config['SQLALCHEMY_DATABASE_URI'] = SQLALCHEMY_DATABASE_URI
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = SQLALCHEMY_TRACK_MODIFICATIONS

# 初始化SQLAlchemy
db = SQLAlchemy(app)

# 导入并注册路由
register_routes(app)

# 创建数据库表
with app.app_context():
    db.create_all()

if __name__ == '__main__':
    from config import HOST, PORT, DEBUG
    app.run(host=HOST, port=PORT, debug=DEBUG)
